package com.dlc.yunguang.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.dlc.commonlibrary.utils.TimeFormats;
import com.dlc.commonlibrary.widget.TitleBar;
import com.dlc.yunguang.adapter.InventoryDetailAdapter;
import com.dlc.yunguang.adapter.decoration.RecyclerSpace;
import com.dlc.yunguang.base.BaseActivity;
import com.dlc.yunguang.model.InventoryRecordBean;
import com.dlc.yunguang.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by YoungeTao on 2017/7/20
 * QQ 2276559259.
 * gmail youngetao@gmail.com
 */

public class InventoryRecordDetailActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    TitleBar mTitleBar;
    @BindView(R.id.recycler_view)
    RecyclerView mRecyclerView;
    @BindView(R.id.tv_location)
    TextView tv_location;
    @BindView(R.id.tv_time)
    TextView tv_time;
    @BindView(R.id.tv_store_record)
    TextView tv_store_record;
    @BindView(R.id.tv_difference_number)
    TextView tv_difference_number;
    @BindView(R.id.tv_inventory_number)
    TextView tv_inventory_number;
    private InventoryRecordBean.DataBean recordBean;

    @Override
    protected int getLayoutID() {
        return R.layout.activity_inventory_record_detail;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTitleBar.leftExit(this);

        mTitleBar.setTitle(R.string.detail);

        InventoryDetailAdapter<InventoryRecordBean.DataBean.SpecGroupBean> adapter = new InventoryDetailAdapter<>();

        Intent intent = getIntent();
        recordBean = (InventoryRecordBean.DataBean) intent.getSerializableExtra("dataBean");

        if(recordBean == null){
            showToast("未查询到数据");
            return;
        }
        tv_location.setText("位置:"+recordBean.getWarehouse()+"--"+"库位"+recordBean.getFrameno());
        tv_time.setText(TimeFormats.formatDateTimeSecend(recordBean.getCtime()*1000));
        tv_store_record.setText("库存记录数量:"+recordBean.getWarecount());
        tv_difference_number.setText("差异数量:"+recordBean.getDiff());
        tv_inventory_number.setText("盘点数量:"+recordBean.getStockcount());

        adapter.setNewData(recordBean.getSpec_group());

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.addItemDecoration(new RecyclerSpace(getResources(), 0, R.dimen.normal_24dp));
        mRecyclerView.setAdapter(adapter);
    }

    @OnClick({R.id.tv_diff_detail})
    public void onBtnClick(View view){
        if(recordBean == null){
            return;
        }
        Intent intent = new Intent(InventoryRecordDetailActivity.this,AbnormalListActivity.class);
        intent.putExtra("rfids",recordBean.getRfids());
        startActivity(intent);
    }

}
